package com.slf.common;

import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Properties;

public class PropsUtil {
    private static final Properties properties = new Properties();

    static {
        // 使用try-with-resources自动关闭流
        try (InputStreamReader reader = new InputStreamReader(
                new FileInputStream("config.properties"),
                StandardCharsets.UTF_8)) {
            properties.load(reader);
        } catch (Exception e) {
            throw new RuntimeException("加载配置文件失败", e);
        }
    }

    public static String getProperty(String keyName) {
        return properties.getProperty(keyName);
    }
}